<template>
  <div class="outer">
    <div class="conditionArea">
      <div class="singleCondition">
        <div class="title">年级</div>
        <div class="showList">
          <div v-for="(item, index) of gradeList" :key="index" :class="['showItem', choGradeId === item.value ? 'activeShow' : '']" @click="handleChoGradeId(item.value)">{{ item.label }}</div>
        </div>
      </div>
      <div class="singleCondition">
        <div class="title">状态</div>
        <div class="showList">
          <div v-for="(item, index) of statusList" :key="index" :class="['showItem', choStatus === item.value ? 'activeShow' : '']" @click="handleChoStatus(item.value)">{{ item.label }}</div>
        </div>
      </div>
      <div class="singleCondition">
        <div class="title">班级</div>
        <div class="showList">
          <div v-for="(item, index) of classList" :key="index" :class="['showItem', choClassName === item ? 'activeShow' : '']" @click="handleChoClassName(item)">{{ item }}</div>
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="btn reset" @click="handleResetCondition">重置</div>
      <div class="btn comfirm" @click="handleComfirmCondition">确定</div>
    </div>
  </div>  
</template>

<script>
export default {
  data () {
    return {
      choGradeId: '',
      choStatus: '',
      choClassName: '',
      gradeList: [{
        label: '全部',
        value: null
      }, {
        label: '高一',
        value: 1
      }, {
        label: '高二',
        value: 2
      }, {
        label: '高三',
        value: 3
      }],
      classList: [],
      statusList: [{
        label: '全部',
        value: null
      }, {
        label: '已激活',
        value: 1
      }, {
        label: '未激活',
        value: 0
      }]
    }
  },
  onLoad () {
    this.createClassList()
  },
  onUnload () {
    this.choGradeId = ''
    this.choStatus = ''
    this.choClassName = ''
  },
  methods: {
    createClassList () {
      let arr = ['全部']
      let str = ''
      for (let i = 1; i < 100; i += 1) {
        str = i + '班'
        arr.push(str)
      }
      this.classList = arr
    },
    handleChoGradeId (val) {
      this.choGradeId = val
    },
    handleChoStatus (val) {
      this.choStatus = val
    },
    handleChoClassName (val) {
      this.choClassName = val
    },
    handleResetCondition () {
      if (this.choGradeId === '' && this.choStatus === '' && this.choClassName === '') {
      } else {
        this.choGradeId = ''
        this.choStatus = ''
        this.choClassName = ''
        wx.showToast({
          title: '已重置筛选条件',
          icon: 'none'
        })
      }
    },
    handleComfirmCondition () {
      if (this.choGradeId === '' && this.choStatus === '' && this.choClassName === '') {
        wx.showToast({
          title: '请选择筛选条件',
          icon: 'none'
        })
      } else {
        let obj = {}
        if (this.choStatus === '' && this.choClassName === '') {
          obj = {
            gradeId: this.choGradeId
          }
        } else if (this.choGradeId === '' && this.choClassName === '') {
          obj = {
            status: this.choStatus
          }
        } else if (this.choGradeId === '' && this.choStatus === '') {
          obj = {
            className: this.choClassName
          }
        } else if (this.choGradeId === '') {
          obj = {
            className: this.choClassName,
            status: this.choStatus
          }
        } else if (this.choStatus === '') {
          obj = {
            className: this.choClassName,
            gradeId: this.choGradeId
          }
        } else if (this.choClassName === '') {
          obj = {
            status: this.choStatus,
            gradeId: this.choGradeId
          }
        } else {
          obj = {
            status: this.choStatus,
            gradeId: this.choGradeId,
            className: this.choClassName
          }
        }
        wx.setStorage({
          key: 'searchConditionObj',
          data: JSON.stringify(obj)
        })
        wx.setStorage({
          key: 'isInSearchCondition',
          data: true
        })
        wx.navigateBack()
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .outer {
    position: relative;
    .conditionArea {
      padding: 59rpx 40rpx 200rpx 50rpx;
      .singleCondition {
        margin-bottom: 20rpx;
        .title {
          color: #171717;
          font-size: 30rpx;
          font-weight: bold;
          margin-bottom: 28rpx;
        }
        .showList {
          display: flex;
          justify-content: flex-start;
          align-items: center;
          flex-wrap: wrap;
          .showItem {
            width: 144rpx;
            height: 60rpx;
            line-height: 60rpx;
            text-align: center;
            background: #FAFAFA;
            color: #999;
            font-size: 26rpx;
            font-weight: bold;
            margin-right: 28rpx;
            margin-bottom: 38rpx;
            border-radius: 5rpx;
          }
          .showItem:nth-child(4n) {
            margin-right: 0;
          }
          .activeShow {
            background: #FFAD0D;
            color: #fff;
          }
        }
      }
    }
    .footer {
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 120rpx;
      background: #fff;
      border-top: 1rpx solid #E5E5E5;
      display: flex;
      justify-content: center;
      align-items: center;
      .btn {
        width: 150rpx;
        height: 60rpx;
        border: 1rpx solid #E5E5E5;
        box-sizing: border-box;
        line-height: 60rpx;
        text-align: center;
        color: #999;
        font-size: 26rpx;
        font-weight: bold;
        border-radius: 5rpx;
      }
      .reset {
        margin-right: 37rpx;
      }
      .comfirm {
        background: #FFAD0D;
        border-color: #FFAD0D;
        color: #fff;
      }
    }
  }
</style>
